<!doctype html>
<html lang="en">

<head>
    <meta charset="utf-8" />
    <title>去向市场管理</title>
    <meta http-equiv="X-UA-Compatible" content="IE=edge" />

    <!-- App favicon -->
    <link rel="shortcut icon" href="assets/images/favicon.ico">

    <!-- App css -->
    <link href="assets/css/bootstrap.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/icons.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/metismenu.min.css" rel="stylesheet" type="text/css" />
    <link href="assets/css/style.css" rel="stylesheet" type="text/css" />
    <link rel="stylesheet" type="text/css" href="assets/css/custom.css" />
    <!-- layer插件 -->
    <link rel="stylesheet" type="text/css" href="plugins/layer2.4/skin/layer.css" />

    <!-- bootstrap-select -->
    <link rel="stylesheet" type="text/css" href="plugins/bootstrap-select/css/bootstrap-select.min.css" />

    <script src="assets/js/modernizr.min.js"></script>

</head>

<body>

    <!-- Begin page -->
    <div id="wrapper">

        <!-- ============================================================== -->
        <!-- 页面内容开始 -->
        <!-- ============================================================== -->

        <!-- Start Page content -->
        <div class="my-content">
            <div class="container-fluid">
                <div class="row">
                    <div class="col-md-12">
                        <div class="card-box">
                            <h4 class="m-t-0 m-b-30 header-title">市场信息</h4>

                            <form class="form-horizontal" role="form">
                                <!-- <div class="form-group row">
                                    <label for="id" class="col-3 col-form-label">去向市场编号</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="id" name="id" placeholder="去向市场编号">
                                    </div>
                                </div> -->
                                <div class="form-group row">
                                    <label for="name" class="col-3 col-form-label">去向市场名称</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="name" name="name"
                                            placeholder="去向市场名称">
                                    </div>
                                </div>
                                <!-- <div class="form-group row">
                                    <label for="province" class="col-3 col-form-label">去向市场所在省</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="province" name="province" placeholder="去向市场所在省">
                                    </div>
                                </div>

                                <div class="form-group row">
                                    <label for="city" class="col-3 col-form-label">去向市场所在市</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="city" name="city" placeholder="去向市场所在市">
                                    </div>
                                </div> -->
                                <!-- <div class="form-group row">
                                    <label for="district" class="col-3 col-form-label">去向市场所在区县</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="district" name="district"
                                            placeholder="去向市场所在区县">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="addr" class="col-3 col-form-label">去向市场地址</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="addr" name="addr"
                                            placeholder="去向市场地址">
                                    </div>
                                </div>-->
                                <!-- <div class="form-group row">
                                    <label for="mark_code" class="col-3 col-form-label">去向市场二维码</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="mark_code" name="mark_code" placeholder="去向市场二维码">
                                    </div>
                                </div> -->
                                <div class="form-group row">
                                    <label for="province" class="col-3 col-form-label">市场所在省份</label>
                                    <div class="col-9">
                                        <input class="form-control" id="province" name="province" readonly="readonly" />

                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="city" class="col-3 col-form-label">市场所在市</label>
                                    <div class="col-9">
                                        <select class="selectpicker form-control" id="city" name="city"
                                            data-live-search="true" data-hide-disabled="ture" data-actions-box="true">
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="district" class="col-3 col-form-label">市场所在区县</label>
                                    <div class="col-9">
                                        <select class="selectpicker form-control" id="district" name="district"
                                            data-live-search="true" data-hide-disabled="ture" data-actions-box="true">
                                        </select>
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="addr" class="col-3 col-form-label">市场地址</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="addr" name="addr"
                                            placeholder="市场地址">
                                    </div>
                                </div>
                                <!-- <div class="form-group row">
                                    <label for="userId" class="col-3 col-form-label">负责人</label>
                                    <div class=" col-9"> -->
                                <!-- <select class="selectpicker form-control" id="userId" name="userId" title="负责人"
                                            data-live-search="true" data-hide-disabled="ture" data-actions-box="true">
                                        </select> -->
                                <!-- <input type="text" class="form-control" id="userId" name="userId" placeholder="负责人">
                                    </div>
                                </div> -->
                                <!-- <div class="form-group row">
                                    <label for="stallName" class="col-3 col-form-label">去向市场档口名称</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="stallName" name="stallName"
                                            placeholder="去向市场档口名称">
                                    </div>
                                </div> -->
                                <div class="form-group row">
                                    <label for="marketLongitude" class="col-3 col-form-label">经度</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="marketLongitude"
                                            name="marketLongitude" placeholder="经度">
                                    </div>
                                </div>
                                <div class="form-group row">
                                    <label for="marketLatitude" class="col-3 col-form-label">纬度</label>
                                    <div class="col-9">
                                        <input type="text" class="form-control" id="marketLatitude"
                                            name="marketLatitude" placeholder="纬度">
                                    </div>
                                </div>
                                <!-- <div class="form-group row">
                                    <label for="stall_code" class="col-3 col-form-label">去向市场二维码</label>
                                    <div class="col-9">
                                        <input type="file" class="form-control" id="stallCodeFile" name="stallCodeFile"
                                            placeholder="去向市场档口二维码">
                                    </div>
                                </div> -->
                                <div class="form-group mb-0 justify-content-end row">
                                    <div class="col-9">
                                        <button type="submit" class="btn btn-primary waves-effect">提交</button>
                                        <button type="button" onclick="layer_close()"
                                            class="btn btn-danger waves-effect">关闭</button>
                                    </div>
                                </div>
                            </form>
                        </div>
                    </div>
                </div>

            </div>
            <!-- container -->

        </div>

        <!-- ============================================================== -->
        <!-- End Right content here -->
        <!-- ============================================================== -->

    </div>
    <!-- END wrapper -->

    <!-- jQuery  -->
    <script src="assets/js/jquery.min.js"></script>
    <script src="assets/js/bootstrap.bundle.min.js"></script>
    <script src="assets/js/metisMenu.min.js"></script>
    <script src="assets/js/waves.js"></script>
    <script src="assets/js/jquery.slimscroll.js"></script>

    <!-- App js -->
    <script src="assets/js/custom.js" type="text/javascript" charset="utf-8"></script>
    <script src="assets/js/jquery.core.js"></script>
    <script src="assets/js/jquery.app.js"></script>
    <script src="assets/js/custom.js" type="text/javascript" charset="utf-8"></script>

    <!-- 表单验证 -->
    <script src="plugins/jquery.form.js/jquery.form.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/jquery.validation.1.14.0/jquery.validate.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/jquery.validation.1.14.0/validate-methods.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/jquery.validation.1.14.0/messages_zh.js" type="text/javascript" charset="utf-8"></script>
    <!-- bootstrap-select -->
    <script src="plugins/bootstrap-select/js/bootstrap-select.js" type="text/javascript" charset="utf-8"></script>

    <!-- layer插件 -->
    <script src="plugins/layer2.4/layer.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/layui2/layui.js" type="text/javascript" charset="utf-8"></script>

    <!-- easyUI -->
    <script src="plugins/jquery-easyUI/jquery.easyui.min.js" type="text/javascript" charset="utf-8"></script>
    <script src="plugins/jquery-easyUI/easyui-lang-zh_CN.js" type="text/javascript" charset="utf-8"></script>

    <!-- datatables插件 -->
    <script type="text/javascript">
        function getProvince(province, city) {
            $('#province').val(province)
            $.ajax({
                type: 'get',
                url: `${URL}toMarket/findCity?province=${province}`,
                dataType: 'json',
                async: false,
                success: (data) => {
                    data = data.object
                    // if (data.length === 0) {
                    //     alert('该市下没有对应的市场')
                    //     return
                    // }
                    let items = ``
                    data = ['中山市']
                    data.forEach(e => {
                        items += `<option value="${e}">${e}</option>`
                    })
                    $('#city').html(items)
                    $("#city").change(() => {
                        city = $("#city").val()
                        getDistrict(province, city) //调用区
                    })
                    getDistrict(province, city)
                    $('.selectpicker').selectpicker('refresh');
                    $('.selectpicker').selectpicker('render');
                },
                error: (data) => {
                    // alert('获取省份失败')
                }
            })
        }

        function getDistrict(province, city) {
            let items = ''
            let data = ['黄圃镇', '南头镇', '东凤镇', '阜沙镇', '小榄镇', '东升镇', '古镇镇', '横栏镇', '三角镇', '民众镇', '南朗镇', '港口镇', '大涌镇',
                '沙溪镇', '三乡镇', '板芙镇', '神湾镇', '坦洲镇'
            ]
            districtName = data[0] //初始化
            data.forEach(e => {
                items += `<option value="${e}">${e}</option>`
            })
            $('#district').html(items)

        }
        $(document).ready(function () {
            getProvince('广东省', '中山市')
        })





        $(function () {
            layui.use('laydate', function () {
                var laydate = layui.laydate;

                //执行一个laydate实例
                laydate.render({
                    elem: '#establishDate', //指定元素
                });
            })

            //获取用户列表
            $.ajax({
                type: "post",
                url: URL + 'findUserAll',
                async: false,
                dataType: "json",
                success: function (data) {
                    for (var i = 0; i < data.length; i++) {
                        var options = $('<option value="' + data[i].personId + '">' + data[i]
                            .username + '    [id=' + data[i].personId + ']' + '</option>')
                        $("#userId").append(options);
                    }
                    $('.selectpicker').selectpicker('refresh');
                    $('.selectpicker').selectpicker('render');
                },
                error: function (XMLHttpRequest, textStatus, errorThrown) {
                    networkError(XMLHttpRequest, textStatus, errorThrown)
                }
            });

            //表单验证
            $("form").validate({
                rules: {
                    // id: {
                    //     required: true,
                    // },
                    name: {
                        required: true,
                    },
                    district: {
                        required: true,
                    },
                    addr: {
                        required: true,
                    },
                    // stallName: {
                    //     required: true,
                    // },
                    // userId: {
                    //     required: true
                    // }
                },
                onkeyup: false,
                focusCleanup: true,
                success: "valid",
                submitHandler: function (form) {
                    var userid = getCookie("userid");
                    var index = parent.layer.getFrameIndex(window.name);
                    $(form).ajaxSubmit({
                        type: "POST",
                        url: URL + "toMarket/add",
                        data: {
                            "createBy": userid,
                            // "district": $('.district').val()
                        },
                        // beforeSend: function () {
                        //     console.log($('#district').val)
                        //     return 
                        // },
                        success: function (data) {
                            parent.layer.msg('添加成功!', {
                                icon: 1,
                                time: 1000
                            });
                            setTimeout(function () {
                                parent.$(".btn-refresh").click();
                                parent.layer.close(index);
                            }, 1000);

                        },
                        error: function (XMLHttpRequest, textStatus, errorThrown) {
                            networkError(XMLHttpRequest, textStatus, errorThrown)
                        }
                    });
                }
            });
        });
    </script>

</body>

</html>